<?php
/**
 * 调拨申请模型
 * @author shipanpan
 */
class Interface_Model_StockTransferApply extends Model_Base {

	public function __construct() {
		$this->db = $this->db();
		$this->writeDb = $this->db("write_db");
	}

	/**
	 * 获取审核通过的调拨申请
	 * @return [type] [description]
	 */
	public function getCheckPass() {

	}

	/**
	 * 调拨申请被wms处理，商品调拨出库
	 * @param  [type] $applyId     调拨申请ID
	 * @param  [type] $goodsSn     调拨商品
	 * @param  [type] $outQuantity 调拨出库数量
	 * @return [type]              [description]
	 */
	public function transferOutWarehouse(int $applyId, $goodsSn, int $outQuantity) {
		$transferApply = $this->writeDb->fethRow('select * from b_stock_transfer_apply where id=' . $applyId);
		if (!$transferApply) {
			return $this->_error('未找到id为：' . $applyId . '的调拨申请记录！');
		}

		if ($transferApply['status'] != '审核通过') {
			return $this->_error('调拨申请记录审核状态为' . $transferApply['status'] . '！');
		}

		if ($transferApply['goodsSn'] != $goodsSn) {
			return $this->_error('调拨记录的商品sku与通知商品sku不符！');
		}

		$updateData = [
			'warehouse_out_quantity' => $outQuantity,
			'transfer_status' => '2',
		];
		$updateWhere = $this->writeDb->quoteInto('id=?', $applyId);
		$this->writeDb->update('b_stock_transfer_apply', $updateData, $updateWhere);

		return true;
	}
}